// components/service-card/service-card.js
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    item: {
      type: Object,
      value: {}
    },
    index: {
      type: Number,
      value: -1
    },
    outerIndex:{
      type: Number,
      value: -1
    },
    canChangeDate: {
      type: Boolean,
      value: false 
    },
    canRadio: {
      type: Boolean,
      value: false 
    },
    canDelete: {
      type: Boolean,
      value: false 
    },
    showDate: {
      type: Boolean,
      value: false 
    },
    canGift:{
      type:Boolean,
      value:false
    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    handleGiftChange(e) {
      this.triggerEvent('handleGiftChange', {
        csa_id:this.properties.item.csa_id
      })
    },
    handleDelete() {
      this.triggerEvent('removeService', 
        {csa_id: this.properties.item.csa_id}) 
    },
    handleDateChange(e) {
      const item=this.properties.item;
      const start_date=e.detail.value;
      item.start_date=start_date;
      item.end_date=new Date(
      new Date(start_date).getTime() + item.service_years*365*24*60*60*1000 
    ).toISOString().split('T')[0];
      this.triggerEvent('bindStartDateChange', { index: this.properties.index, item })
    },
    handleRadioChange(e) {
      this.triggerEvent('onRadioChange', {
        csa_id:this.properties.item.csa_id,
        outerIndex: this.properties.outerIndex,
      }) 
    }
  }
})